module.exports = function ($scope, $modalInstance, FileUploader,$resource, $modal, item, flag, toaster){
    

  
   
    init();
    function init(){
        $scope.opeinfo = flag ? {'flag': true} : angular.copy(item);
        console.log($scope.opeinfo);
        
    }
   
    //保存
    $scope.save = function (){
        var url =  $scope.opeinfo.flag ? '/api/as/mc/headline/insert' : '/api/as/mc/headline/update';
        $resource(url, {}, {}).save($scope.opeinfo, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

 


  

    //logo
    var uploader = $scope.uploader = new FileUploader({
        url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=skv4&selfdir=headlinelogo'+ Date.parse(new Date())
    });

    uploader.filters.push({
        name: 'imageFilter',
        fn: function(item /*{File|FileLikeObject}*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
    });    
    uploader.onSuccessItem = function(fileItem, response, status, headers) {
        $scope.opeinfo.logo = response.savename; 
        
    };


     //img
    $scope.img = new FileUploader({
        url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=skv4&selfdir=headlineimg'+ Date.parse(new Date())
    });
    $scope.img.filters.push({
        name: 'imageFilter',
        fn: function (item /*{File|FileLikeObject}*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
    });
    $scope.img.onSuccessItem = function (fileItem, response, status, headers) {
        $scope.opeinfo.img = response.savename;
    };



    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }
};